import { Component, OnInit, ViewChild } from '@angular/core';
import { NzFormatEmitEvent } from 'ng-zorro-antd/tree';
import { NzMessageService } from 'ng-zorro-antd/message';
import { HomeService } from '../../../apis/users.service'
import { Subscription } from 'rxjs'; // 离开页面时使用Subscription取消请求

export interface Person {
  key: string;
  name: string;
  age: number;
  role: string;
}
@Component({
  selector: 'app-users',
  templateUrl: './users.component.html',
  styleUrls: ['./users.component.scss']
})
export class UsersComponent implements OnInit {
  @ViewChild('handleOpen')
  pageIndex: number = 1
  private subscription: Subscription | undefined
  nodes = [
    {
      title: '西南',
      key: '00',
      children: [
        {
          title: '技术部',
          key: '000',
          isLeaf: true
        },
        {
          title: '人力资源部',
          key: '001',
          isLeaf: true
        },
        {
          title: '行政部',
          key: '002',
          isLeaf: true
        }
      ]
    },
    {
      title: '华南',
      key: '01',
      children: [
        {
          title: '技术部',
          key: '010',
          isLeaf: true
        },
        {
          title: '人力资源部',
          key: '011',
          isLeaf: true
        },
        {
          title: '行政部',
          key: '012',
          isLeaf: true
        }
      ]
    },
  ]

  columns = [
    {
      title: 'ID',
      dataIndex: 'id',
      fixed: 'center',
      width: '200px',
    },
    {
      title: '姓名',
      dataIndex: 'name',
      width: '150px',
      filters: [
        { text: 'Male', value: 'male' },
        { text: 'Female', value: 'female' },
      ],
    },
    {
      title: '地址',
      dataIndex: 'address',
    },
    {
      title: '编号',
      dataIndex: 'no',
      width: '150px',
    },
    {
      title: '开始时间',
      width: '150px',
      dataIndex: 'beginTime',
    },
    {
      title: '结束时间',
      width: '150px',
      dataIndex: 'endTime',
    }
   ]

   dataSource:any = []
  
  constructor(private nzMessageService: NzMessageService, private homeService: HomeService) { }
  // 删除取消和确认
  cancel(): void {
    this.nzMessageService.info('click cancel');
  }
  confirm(e: string): void {
    console.log(e,'eee', this.pageIndex);
    
    this.nzMessageService.success('success');

  }
  // tree
  nzEvent(event: NzFormatEmitEvent): void {
    console.log(event);
  }

  // 
  pageIndexChange(e: number) {
    console.log('fffffffff', e);
  }

  ngOnInit(): void {
    this.subscription = this.homeService.getHomeList().subscribe({
      next: (data: any) => {
        console.log(data,'dddddddddddddddddd888888888888888888')
      },
      error: (err) => {
        console.log(err,'err');
        
      }
    })
    for (let index = 0; index < 40; index++) {
      this.dataSource.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
  }

  ngOnDestroy():void{
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }

}
